package com.szrt.day20170418.ch05;





import org.junit.Test;

import com.szrt.utils.ArrayUtil;

public class PetDaoTest {
	
	
	
	@Test
	public void updatePetByConditionsTest() throws Exception {
		PetDao  dao = new  PetDaoImpl();
		
		
		PetShop huayun = new PetShop();
		huayun.setName("华润商店");
		
		//初始化宠物笼子的代码
		Pet[] pets = new Pet[5];
		huayun.setPets(pets );
		
		Cat cat  = new Cat("咖啡猫",2,"红色");
		dao.addPet(huayun, cat);
		
		
		Cat jqm  = new Cat("机器猫",8,"红色");
		dao.addPet(huayun, jqm);
		
		
		Cat duomeng  = new Cat("哆啦A梦",8,"绿色");
		dao.addPet(huayun, duomeng);
		
		Dog dog = new Dog("八公",8,"红色");
		dao.addPet(huayun, dog);
		
		//数据初始化成功
		
		String color = "红色";
		int age =8;
		
		
		//封装好条件  String name, int age, String color
		Pet conditions =new Cat(null,age,color);
		
		String afterColor="绿色";
		Pet after= new Cat(null,18,afterColor);
		Pet[] jieguos = dao.updatePetByConditions(huayun, conditions, after);
		
		ArrayUtil.printArry(jieguos);
	}
	
	@Test
	public void updateByConditionTest() throws Exception {
		PetDao  dao = new  PetDaoImpl();
		
		
		PetShop huayun = new PetShop();
		huayun.setName("华润商店");
		
		//初始化宠物笼子的代码
		Pet[] pets = new Pet[5];
		huayun.setPets(pets );
		
		Cat cat  = new Cat("咖啡猫",2,"红色");
		dao.addPet(huayun, cat);
		
		Cat duomeng  = new Cat("哆啦A梦",8,"绿色");
		dao.addPet(huayun, duomeng);
		
		Dog dog = new Dog("八公",8,"红色");
		dao.addPet(huayun, dog);
		
		
		String color = "红色";
		int age =8;
		
		
		//封装好条件  String name, int age, String color
		Pet conditions =new Cat(null,age,color);
		
		String afterName="京巴狗狗..";
		Pet after= new Dog(afterName);
		
		
		
		Pet jieguo =dao.updateByCondition(huayun, conditions, after);
		
		System.out.println(jieguo);
		
	}
	
	/**
	 * 类 PetDaoImpl  中的方法   addPet
	 * @throws Exception
	 */
	@Test
	public void findPetsByAgeTest() throws Exception {
		
		PetDao  dao = new  PetDaoImpl();
		
		
		PetShop huayun = new PetShop();
		huayun.setName("华润商店");
		
		//初始化宠物笼子的代码
		Pet[] pets = new Pet[5];
		huayun.setPets(pets );
		
		Cat cat  = new Cat("咖啡猫",2);
		dao.addPet(huayun, cat);
		
		Cat duomeng  = new Cat("哆啦A梦",8);
		dao.addPet(huayun, duomeng);
		
		Dog dog = new Dog("八公",8);
		dao.addPet(huayun, dog);
		
		
		//准备好了初始数据
		Pet[] chongwus = dao.findPetsByAge(huayun, 8);
		ArrayUtil.printArry(chongwus);
		
		
	}
	
	
	@Test
	public void addPetTest() throws Exception {
		
		PetDao  dao = new  PetDaoImpl();
		
		Pet[] pets = new Pet[1];
		PetShop huayun = new PetShop("华润商店",pets);
		//huayun.setName("华润商店");
		
		//初始化宠物笼子的代码
		//Pet[] pets = new Pet[1];
		//huayun.setPets(pets );
		
		Cat cat  = new Cat("咖啡猫");
		dao.addPet(huayun, cat);
		
		Dog dog = new Dog("八公");
		dao.addPet(huayun, dog);
		
		
		dao.findPetByName(huayun, "咖啡猫");
		
		
		Tiger tiger = new Tiger("吊睛白额大虎");
		
		//dao.addPet(huayun, tiger);
	}

}
